package com.lh.java.basic.reflect;


public class TestGetObjectReflect {

	/**
	 * 功能描述  
	 * @Author: lh  2013-3-22 下午05:11:42
	 */
	public static void main(String[] args) {
		String clasName = "com.lh.java.basic.reflect.Student";
		Student s = (Student) getObjectReflect(clasName);
		s.setAge(5);
		s.setName("hah");
		System.out.println(s);
	}
	public static Object getObjectReflect(String name) {
		try {
			//得到对象
			Class c = Class.forName(name);
			Object yourObj = c.newInstance();
			return yourObj;
//			//得到方法
//			Method methlist[] = cls.getDeclaredMethods();
//			for (int i = 0; i < methlist.length; i++) {
//			Method m = methlist[i];
//			}
//			//获取到方法对象,假设方法的参数是一个int,method名为setAge
//			Method sAge = c.getMethod("setAge", new Class[] {int.class});
//			//获得参数Object
//			Object[] arguments = new Object[] { new Integer(37)};
//			//执行方法
//			sAge.invoke(yourObj , arguments);
			} catch (Exception e) {
			}
		return null;  
	}

}
class Student {
	private String name;
	private int age;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	@Override
	public String toString() {		
		return "name="+this.name+"  age="+this.age;
	}
}
